*******************************************************
* .do-file to produce lc profiles to compare to SCF 
*******************************************************

clear all
set maxvar 7000

use "$psidwkddata/famind_combined_adj_sing.dta", clear


///////////////////////////
/////// HOUSEKEEPING //////
///////////////////////////

// only keep reference person (graphs are on HH level)
keep if ref == 1

// net worth (currently called wealth, rename)
rename wealth nworth

// winsorize net worth (as done in SCF)
winsor2 nworth, cuts(1 99)
replace nworth = nworth_w
drop nworth_w

// create unique person ID for reference person
gen uniqueid_ref = (famid68*1000) + persid if ref    == 1

// set as survey
svyset uniqueid_ref [pweight = famweight] 


***************************************************
************ LIFE CYCLE GRAPHS ********************
***************************************************

		/// Stock Market Participation -- without stocks in retirement accounts

		gen ci_low  = . 
		gen ci_high = . 
		gen mSMP    = . 
		
		foreach x of numlist 0/2 {
		foreach num of numlist 30(1)65 {
		di `num'
		svy: mean stocks if ageav == `num' & fam_type == `x'
		mat A = r(table) 
		replace mSMP    = A[rownumb(A, "b"),1 ]  if ageav == `num' & fam_type == `x'
		replace ci_low  = A[rownumb(A, "ll"),1 ] if ageav == `num' & fam_type == `x'
		replace ci_high = A[rownumb(A, "ul"),1 ] if ageav == `num' & fam_type == `x'
		}
		}
		
		preserve
		keep mSMP ageav fam_type ci_low ci_high
		keep if ageav >= 30 & ageav <=65
		duplicates drop
		sort ageav
		
		tw (line mSMP ageav if fam_type == 2 , lc(black) lw(medium)) ///
		(line ci_low  ageav if fam_type == 2 , lc(black*0.15) lw(thin)) ///
		(line ci_high ageav if fam_type == 2 , lc(black*0.15) lw(thin))  /// 
		(line ci_low  ageav if fam_type == 0, lp(solid) lc(black*0.15) lw(thin)) ///
		(line mSMP ageav    if fam_type == 0, lp(dash_dot) lc(black) lw(medium)) ///
		(line ci_high ageav if fam_type == 0, lp(solid) lc(black*0.15) lw(thin)) ///  
		(line ci_high ageav if fam_type == 1, lp(solid) lc(black*0.15) lw(thin)) ///
		(line ci_low ageav  if fam_type == 1, lp(solid) lc(black*0.15) lw(thin)) ///
		(line mSMP ageav    if fam_type == 1, lp(dash)  lc(black) lw(medium)) ,  /// 
		xtitle("Age", siz(vlarge)) ytitle("Participation Rate", size(vlarge))  ///
		legend(order(1 "Couples" 5 "Men" 9 "Women") size(vlarge) ///
		position(6) col(4) region(lcolor(white)) stack) ///
		graphregion(color(white)) xlabel(30(10)65,labsize(vlarge)) ylabel(0(.2)0.6,labsize(vlarge))
		graph export "$resultpath/SMP_PSID.eps", replace
		graph export "$resultpath/SMP_PSID.pdf", replace
		restore
		
		
		/// Net Worth
		drop ci* 
		gen ci_low  = . 
		gen ci_high = . 
		gen mnworth    = . 
		
		foreach x of numlist 0/2 {
		foreach num of numlist 30(1)65 {
			
		svy: mean nworth if ageav == `num' & fam_type == `x'
		mat A = r(table)
		replace  mnworth = A[rownumb(A, "b"),1 ] if ageav == `num' & fam_type == `x'
		replace ci_low  = A[rownumb(A, "ll"),1 ] if ageav == `num' & fam_type == `x'
		replace ci_high = A[rownumb(A, "ul"),1 ] if ageav == `num' & fam_type == `x'
		}
		}
		
		preserve
		keep mnworth ageav fam_type ci_low ci_high
		keep if ageav >= 30 & ageav <=65
		duplicates drop

		replace mnworth = mnworth / 1000
		replace ci_high = ci_high / 1000
		replace ci_low = ci_low / 1000
		
		sort ageav
		 tw (line mnworth ageav if fam_type == 2 , lc(black) lw(medium)) ///
		(line ci_low ageav  if fam_type == 2 , lc(black*0.15) lw(thin)) ///
		(line ci_high ageav if fam_type == 2 , lc(black*0.15) lw(thin)) /// 
		(line ci_low ageav  if fam_type == 0, lp(solid) lc(black*0.15) lw(thin)) ///
		(line mnworth ageav if fam_type == 0, lp(dash_dot) lc(black) lw(medium)) ///
		(line ci_high ageav if fam_type == 0, lp(solid) lc(black*0.15) lw(thin)) /// 
		(line ci_high ageav if fam_type == 1, lp(solid) lc(black*0.15) lw(thin)) ///
		(line ci_low ageav  if fam_type == 1, lp(solid) lc(black*0.15) lw(thin)) ///
		(line mnworth ageav if fam_type == 1, lp(dash)  lc(black) lw(medium)) ,  /// 
		xtitle("Age", siz(vlarge)) ytitle("Net Worth in (000s) 2007 \$", size(vlarge))  ///
		legend(order(1 "Couples" 5 "Men" 9 "Women") size(vlarge) ///
		position(6) col(4) region(lcolor(white)) stack) ///
		graphregion(color(white)) xlabel(30(10)65,labsize(vlarge)) ylabel(,labsize(vlarge))
		graph export "$resultpath/networth_PSID.eps", replace
		graph export "$resultpath/networth_PSID.pdf", replace
		restore
		